//RSA公钥
var publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCukkeTS1QnLB65tR90sgwc1jDenKh0xfiYO/3bVUjxyTC1ar5bE/UozhGpwG11+BygazLKP8STATy/i957hj7tpTd0VJdC30war99rcrTK4ozhnZCatd2Fz2cfwVpT7tu4SLIeFXVqYHYIhidnd0Hl9Dn1I4vLUsDmQyyecF7hlwIDAQAB';

<!--AES随机key-->
function randomWord(randomFlag, min, max){
    var str = "",
        range = min,
        arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
    // 随机产生
    if(randomFlag){
        range = Math.round(Math.random() * (max-min)) + min;
    }
    for(var i=0; i<range; i++){
        pos = Math.round(Math.random() * (arr.length-1));
        str += arr[pos];
    }
    return str;
}

<!--AES加解密-->
function Encrypt(data,aesKey){
    var key = CryptoJS.enc.Utf8.parse(aesKey);
    var srcs = CryptoJS.enc.Utf8.parse(data);
    var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
    return encrypted.toString();
}
function Decrypt(data,aesKey){
    var key = CryptoJS.enc.Utf8.parse(aesKey);
    var decrypt = CryptoJS.AES.decrypt(data, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});
    return CryptoJS.enc.Utf8.stringify(decrypt).toString();
}

<!--RSA加密-->
function RSAEncrypt(str) {
    var encrypt = new JSEncrypt();
    encrypt.setPublicKey(publicKey);
    var data = encrypt.encrypt(str);
    return data;
}

function RSADncrypt(str) {
    var encrypt = new JSEncrypt();
    encrypt.setPrivateKey(publicKey);
    var data = encrypt.decrypt(str);
    return data;
}





